<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="85px">
      <el-form-item label="储位编号" prop="storeLocNo">
        <el-input v-model="queryParams.storeLocNo" placeholder="请输入储位编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="储位名称" prop="storeLocName">
        <el-input v-model="queryParams.storeLocName" placeholder="请输入储位名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="库区" prop="whAreaId">
        <el-select v-model="queryParams.whAreaId" placeholder="请选择库区" @change="getMessageOption" clearable>
          <el-option v-for="dict in optionss" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="存放区" prop="storeAreaId">
        <el-select v-model="queryParams.storeAreaId" placeholder="请选择存放区" clearable>
          <el-option v-for="dict in messageOption" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['storage:mdStockPosInfo:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['storage:mdStockPosInfo:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['storage:mdStockPosInfo:remove']">删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="mdStockPosInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="储位标识" align="center" prop="storeLocId" />
      <el-table-column label="操作标识" align="center" prop="operId" v-if="false" />
      <el-table-column label="储位编号" align="center" prop="storeLocNo" />
      <el-table-column label="储位条形码" align="center" prop="storeLocBarCode" min-width="100px" />
      <el-table-column label="储位实际顺序号" align="center" prop="storeLocOrder" min-width="180px" />
      <el-table-column label="储位类型" align="center" prop="storeType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sl_store_type" :value="scope.row.storeType" />
        </template>
      </el-table-column>
      <el-table-column label="周转柜资产编号" align="center" prop="cabinetBarCode" min-width="180px" />
      <el-table-column label="柜单元标识" align="center" prop="unitId" min-width="100px" />
      <el-table-column label="柜单元出厂编号" align="center" prop="unitMadeNo" min-width="180px" />
      <el-table-column label="库房编号" align="center" prop="whId" />
      <el-table-column label="库房名称" align="center" prop="whName" min-width="180px" />
      <el-table-column label="库区编号" align="center" prop="whAreaId" />
      <el-table-column label="库区名称" align="center" prop="whAreaname" min-width="110px" />
      <el-table-column label="存放区标识" align="center" prop="storeAreaId" min-width="100px" />
      <el-table-column label="存放区名称" align="center" prop="storeAreaName" min-width="100px" />
      <el-table-column label="储位状态" align="center" prop="statusCode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sl_status_code" :value="scope.row.statusCode" />
        </template>
      </el-table-column>
      <el-table-column label="档案创建时间" align="center" prop="createTime" min-width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最后一次修改时间" align="center" prop="updateTime" min-width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="储位地址" align="center" prop="posAddress" />
      <el-table-column label="主控板地址" align="center" prop="scmaddress" min-width="100px" />
      <el-table-column label="管理单位" align="center" prop="deptNo" />
      <el-table-column label="名称" align="center" prop="storeLocName" />
      <el-table-column label="存放设备类别" align="center" prop="equipTypeCode" min-width="110px">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sl_equip_type_code" :value="scope.row.equipTypeCode" />
        </template>
      </el-table-column>
      <el-table-column label="可存放设备数量" align="center" prop="storeEquipNum" min-width="150px" />
      <el-table-column label="可存放周转箱数量" align="center" prop="rotateBoxNum" min-width="180px" />
      <el-table-column label="描述" align="center" prop="description" min-width="280px" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" min-width="150px">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['storage:mdStockPosInfo:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['storage:mdStockPosInfo:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改储位信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" v-if="title == '添加储位信息'">
        <el-row>
          <el-col :span="11">
            <el-form-item label="储位标识" prop="storeLocId">
              <el-input v-model="form.storeLocId" placeholder="请输入储位标识" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="操作标识" prop="operId" v-if="false">
              <el-input v-model.number="form.operId" placeholder="请输入操作标识" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="储位编号" prop="storeLocNo">
              <el-input v-model="form.storeLocNo" placeholder="请输入储位编号" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="储位条形码" prop="storeLocBarCode">
              <el-input v-model="form.storeLocBarCode" placeholder="请输入储位条形码" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="储位实际顺序号" prop="storeLocOrder">
              <el-input v-model="form.storeLocOrder" placeholder="请输入储位实际顺序号" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="储位类型" prop="storeType">
              <el-select v-model="form.storeType" placeholder="请选择储位类型" clearable>
                <el-option v-for="dict in dict.type.sl_store_type" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="周转柜资产编号" prop="cabinetBarCode">
              <el-input v-model="form.cabinetBarCode" placeholder="请输入周转柜资产编号" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="柜单元标识" prop="unitId">
              <el-input v-model.number="form.unitId" placeholder="请输入柜单元标识" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="柜单元出厂编号" prop="unitMadeNo">
              <el-input v-model="form.unitMadeNo" placeholder="请输入柜单元出厂编号" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="库房" prop="whId">
              <el-select v-model="form.whId" placeholder="请选择库房" @change="changeWhId">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="库区" prop="whAreaId">
              <el-select v-model="form.whAreaId" placeholder="请选择库区" @change="changeWhAreaId">
                <el-option v-for="item in option" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="存放区" prop="storeAreaId">
              <el-select v-model="form.storeAreaId" placeholder="请选择存放区">
                <el-option v-for="item in mdStorageOptions" :key="item.value" :label="item.label"
                  :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="储位状态" prop="statusCode">
              <el-select v-model="form.statusCode" placeholder="请选择储位状态" clearable>
                <el-option v-for="dict in dict.type.sl_status_code" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="储位地址" prop="posAddress">
              <el-input v-model="form.posAddress" placeholder="请输入储位地址" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="主控板地址" prop="scmaddress">
              <el-input v-model="form.scmaddress" placeholder="请输入主控板地址" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="管理单位" prop="deptNo">
              <el-input v-model="form.deptNo" placeholder="请输入管理单位" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="储位名称" prop="storeLocName">
              <el-input v-model="form.storeLocName" placeholder="请输入储位名称" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="存放设备类别" prop="equipTypeCode">
              <el-select v-model="form.equipTypeCode" placeholder="请选择存放设备类别" clearable>
                <el-option v-for="dict in dict.type.sl_equip_type_code" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="设备数量" prop="storeEquipNum">
              <el-input v-model.number="form.storeEquipNum" placeholder="请输入可存放设备数量" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="周转箱数量" prop="rotateBoxNum">
              <el-input v-model.number="form.rotateBoxNum" placeholder="请输入可存放周转箱数量" />
            </el-form-item>
          </el-col>
          <el-col :span="22">
            <el-form-item label="描述" prop="description">
              <el-input type="textarea" :autosize="{ minRows: 5, maxRows: 5 }" v-model="form.description"
                placeholder="请输入描述" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-form ref="forms" :model="forms" :rules="rules" label-width="120px" v-if="title == '修改储位信息'">
        <el-row>
          <el-col :span="11">
            <el-form-item label="储位标识" prop="storeLocId">
              <el-input v-model="forms.storeLocId" placeholder="请输入储位标识" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="操作标识" prop="operId" v-if="false">
              <el-input v-model.number="forms.operId" placeholder="请输入操作标识" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="储位编号" prop="storeLocNo">
              <el-input v-model="forms.storeLocNo" placeholder="请输入储位编号" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="储位条形码" prop="storeLocBarCode">
              <el-input v-model="forms.storeLocBarCode" placeholder="请输入储位条形码" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="储位实际顺序号" prop="storeLocOrder">
              <el-input v-model="forms.storeLocOrder" placeholder="请输入储位实际顺序号" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="储位类型" prop="storeType">
              <el-select v-model="forms.storeType" placeholder="请选择储位类型" clearable>
                <el-option v-for="dict in dict.type.sl_store_type" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="周转柜资产编号" prop="cabinetBarCode">
              <el-input v-model="forms.cabinetBarCode" placeholder="请输入周转柜资产编号" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="柜单元标识" prop="unitId">
              <el-input v-model.number="forms.unitId" placeholder="请输入柜单元标识" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="柜单元出厂编号" prop="unitMadeNo">
              <el-input v-model="forms.unitMadeNo" placeholder="请输入柜单元出厂编号" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="库房" prop="whId">
              <el-select v-model="forms.whId" placeholder="请选择库房" @change="changeWhId">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="库区" prop="whAreaId">
              <el-select v-model="forms.whAreaId" placeholder="请选择库区" @change="changeWhAreaId">
                <el-option v-for="item in option" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="存放区" prop="storeAreaId">
              <el-select v-model="forms.storeAreaId" placeholder="请选择存放区">
                <el-option v-for="item in mdStorageOptions" :key="item.value" :label="item.label"
                  :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="储位状态" prop="statusCode">
              <el-select v-model="forms.statusCode" placeholder="请选择储位状态" clearable>
                <el-option v-for="dict in dict.type.sl_status_code" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="储位地址" prop="posAddress">
              <el-input v-model="forms.posAddress" placeholder="请输入储位地址" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="主控板地址" prop="scmaddress">
              <el-input v-model="forms.scmaddress" placeholder="请输入主控板地址" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="管理单位" prop="deptNo">
              <el-input v-model="forms.deptNo" placeholder="请输入管理单位" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="储位名称" prop="storeLocName">
              <el-input v-model="forms.storeLocName" placeholder="请输入储位名称" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="存放设备类别" prop="equipTypeCode">
              <el-select v-model="forms.equipTypeCode" placeholder="请选择存放设备类别" clearable>
                <el-option v-for="dict in dict.type.sl_equip_type_code" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="设备数量" prop="storeEquipNum">
              <el-input v-model.number="forms.storeEquipNum" placeholder="请输入可存放设备数量" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="周转箱数量" prop="rotateBoxNum">
              <el-input v-model.number="forms.rotateBoxNum" placeholder="请输入可存放周转箱数量" />
            </el-form-item>
          </el-col>
          <el-col :span="22">
            <el-form-item label="描述" prop="description">
              <el-input type="textarea" :autosize="{ minRows: 5, maxRows: 5 }" v-model="forms.description"
                placeholder="请输入描述" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMdStockPosInfo, getMdStockPosInfo, delMdStockPosInfo, addMdStockPosInfo, updateMdStockPosInfo } from "@/api/storage/mdStockPosInfo";
import { selectMdWhInfo, selectMdStorageAreaInfo, selectMdSaInfo } from "@/api/storage/mdWhInfo";

export default {
  name: "MdStockPosInfo",
  dicts: ['sl_store_type', 'sl_status_code', 'sl_equip_type_code'],
  data() {
    //自定义验证表单数聚长度
    let operIdValidate = (rule, value, callback) => {
      if (value) {
        if (value.length > 16) {
          callback(new Error("输入长度不得长于16个字符"))
        } else {
          callback()
        }
      } else {
        callback()
      }
    };
    let rowValidate = (rule, value, callback) => {
      if (value) {
        if (value.length > 5) {
          callback(new Error("输入长度不得长于5个字符"))
        } else {
          callback()
        }
      } else {
        callback()
      }
    };
    let mValidate = (rule, value, callback) => {
      if (value) {
        if (value.length > 256) {
          callback(new Error("输入长度不得长于256个字符"))
        } else {
          callback()
        }
      } else {
        callback()
      }
    };
    let numberValidate = (rule, value, callback) => {
      if (value) {
        if (value.length > 32) {
          callback(new Error("输入长度不得长于32个字符"))
        } else {
          callback()
        }
      } else {
        callback()
      }
    };
    let maxValidate = (rule, value, callback) => {
      if (value) {
        if (value.length > 64) {
          callback(new Error("输入长度不得长于64个字符"))
        } else {
          callback()
        }
      } else {
        callback()
      }
    };
    let minValidate = (rule, value, callback) => {
      if (value) {
        if (value.length > 11) {
          callback(new Error("输入长度不得长于11个字符"))
        } else {
          callback()
        }
      } else {
        callback()
      }
    };
    let eightValidate = (rule, value, callback) => {
      if (value) {
        if (value.length > 8) {
          callback(new Error("输入长度不得长于8个字符"))
        } else {
          callback()
        }
      } else {
        callback()
      }
    }
    return {
      disabled: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 储位信息表格数据
      mdStockPosInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        operId: null,
        storeLocNo: null,
        storeLocBarCode: null,
        storeLocOrder: null,
        storeType: null,
        cabinetBarCode: null,
        unitId: null,
        unitMadeNo: null,
        whId: null,
        whAreaId: null,
        storeAreaId: null,
        statusCode: null,
        createTime: null,
        updateTime: null,
        posAddress: null,
        scmaddress: null,
        deptNo: null,
        storeLocName: null,
        equipTypeCode: null,
        storeEquipNum: null,
        rotateBoxNum: null,
        description: null
      },
      // 表单参数
      form: {},
      forms: {},
      // 表单校验
      rules: {
        //储位标识
        storeLocId: [{
          required: true,
          message: '储位标识不能为空',
          trigger: 'blur'
        },
        {
          pattern: /^[1-9]\d{0,15}$/,
          message: '储位标识不能为0，长度不得超过16位数字'
        },
        ],
        //储位条形码
        storeLocBarCode: [{
          required: false,
          validator: numberValidate,
          trigger: 'blur'
        }],
        //储位实际顺序号
        storeLocOrder: [
          {
            required: false,
            validator: eightValidate,
            trigger: 'blur'
          }],
        //储位状态
        statusCode: [{
          required: true,
          message: '储位状态不能为空',
          trigger: 'change'
        }],
        //储位地址
        posAddress: [{
          required: false,
          validator: operIdValidate,
          trigger: 'blur'
        }],
        //管理单位
        deptNo: [{
          required: true,
          message: '管理单位不能为空',
          trigger: 'blur'
        }, {
          // min: 3,
          max: 16,
          message: '长度不得超过16个字符',
          trigger: 'blur'
        }],
        //存放设备类别
        equipTypeCode: [{
          required: true,
          message: '存放设备类别不能为空',
          trigger: 'change'
        }],
        //库房标识
        whId: [{
          required: true,
          message: '库房不能为空',
          trigger: 'change'
        }],
        //库区标识
        whAreaId: [{
          required: true,
          message: '库区不能为空',
          trigger: 'change'
        }],
        //储位名称
        storeLocName: [{
          required: true,
          message: '管理单位不能为空',
          trigger: 'blur'
        }, {
          // min: 3,
          max: 256,
          message: '长度不得超过256个字符',
          trigger: 'blur'
        }],
        //存放区标识
        storeAreaId: [{
          required: true,
          message: '存放区不能为空',
          trigger: 'change'
        }],
        //操作标识
        operId: [{
          required: false,
          validator: operIdValidate,
          trigger: 'blur'
        }],
        //储位编号
        storeLocNo: [
          {
            required: true,
            message: '储位编号不能为空',
            trigger: 'blur'
          }, {
            // min: 3,
            max: 16,
            message: '长度不得超过16个字符',
            trigger: 'blur'
          }],
        //周转柜资产编号
        cabinetBarCode: [{
          required: false,
          validator: maxValidate,
          trigger: 'blur'
        }],
        //柜单元标识
        unitId: [{
          required: false,
          validator: operIdValidate,
          trigger: 'blur'
        }],
        //柜单元出厂编号
        unitMadeNo: [{
          required: false,
          validator: numberValidate,
          trigger: 'blur'
        }],
        //主控板地址
        scmaddress: [{
          required: false,
          validator: operIdValidate,
          trigger: 'blur'
        }],
        //可存放设备数量
        storeEquipNum: [{
          required: true,
          message: '可存放设备数量不能为空',
          trigger: 'blur'
        }, {
          // min: 3,
          max: 5,
          message: '长度不得超过5个字符',
          trigger: 'blur'
        }],
        //可存放周转箱数量
        rotateBoxNum: [{
          required: true,
          message: '可存放周转箱数量不能为空',
          trigger: 'blur'
        }, {
          // min: 3,
          max: 5,
          message: '长度不得超过5个字符',
          trigger: 'blur'
        }],
        //描述
        description: [{
          required: false,
          validator: mValidate,
          trigger: 'blur'
        }],
        //储位类型
        storeType: [{
          required: true,
          message: '存放设备类别不能为空',
          trigger: 'change'
        }]
      },
      //库房下拉框
      options: [],
      //库区下拉框
      option: [],
      //存放区下拉框
      mdStorageOptions: [],
      //库区查询参数
      querySelsctParams: {
        whId: null
      },
      //存放区查询参数
      queryMdOptionsParams: {
        whId: null,
        whAreaId: null
      },
      //查询参数库区下拉框
      optionss: [],
      //查询参数存放区下拉框
      messageOption: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询储位信息列表 */
    getList() {
      this.loading = true;
      listMdStockPosInfo(this.queryParams).then(response => {
        this.mdStockPosInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      this.getSelect()
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 转换层格数据结构 */
    normalizerGrid(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.storeAreaId,
        label: node.storeAreaName,
        children: node.children
      };
    },
    // 表单重置
    reset() {
      this.form = {
        storeLocId: null,
        operId: null,
        storeLocNo: null,
        storeLocBarCode: null,
        storeLocOrder: null,
        storeType: null,
        cabinetBarCode: null,
        unitId: null,
        unitMadeNo: null,
        whId: null,
        whAreaId: null,
        storeAreaId: null,
        statusCode: null,
        createTime: null,
        updateTime: null,
        posAddress: null,
        scmaddress: null,
        deptNo: null,
        storeLocName: null,
        equipTypeCode: null,
        storeEquipNum: null,
        rotateBoxNum: null,
        description: null
      };
      this.forms = {
        operId: null,
        storeLocNo: null,
        storeLocBarCode: null,
        storeLocOrder: null,
        storeType: null,
        cabinetBarCode: null,
        unitId: null,
        unitMadeNo: null,
        whId: null,
        whAreaId: null,
        storeAreaId: null,
        statusCode: null,
        createTime: null,
        updateTime: null,
        posAddress: null,
        scmaddress: null,
        deptNo: null,
        storeLocName: null,
        equipTypeCode: null,
        storeEquipNum: null,
        rotateBoxNum: null,
        description: null
      }
      this.resetForm("form");
      this.resetForm("forms")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.storeLocId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.form.statusCode = "01";
      this.form.equipTypeCode = "01";
      this.form.storeType = "01"
      this.open = true;
      this.title = "添加储位信息";
      selectMdWhInfo().then(response => {
        this.options = response.data
        this.form.whId = this.options[0].value
        this.changeWhId()
      })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const storeLocId = row.storeLocId || this.ids
      getMdStockPosInfo(storeLocId).then(response => {
        this.forms = response.data;
        this.open = true;
        this.title = "修改储位信息";
        selectMdWhInfo().then(response => {
          this.options = response.data
        })
        this.changeWhId()
        this.changeSelectChange()
      });
    },
    /** 提交按钮 */
    submitForm() {
      let mdStockPosInfoList = JSON.parse(JSON.stringify(this.mdStockPosInfoList))
      if (this.title == "修改储位信息") {
        updateMdStockPosInfo(this.forms).then(response => {
          this.$modal.msgSuccess("修改成功");
          this.open = false;
          this.getList();
        });
      } else if (this.title == "添加储位信息") {
        let item = mdStockPosInfoList.find(value => {
          return value.storeLocId == this.form.storeLocId
        })
        if (item == undefined) {
          this.$refs["form"].validate(valid => {
            if (valid) {
              addMdStockPosInfo(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          })
        } else {
          this.$message.error('您输入的储位标识重复，请重新输入');
        }
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const storeLocIds = row.storeLocId || this.ids;
      this.$modal.confirm('是否确认删除储位信息编号为"' + storeLocIds + '"的数据项？').then(function () {
        return delMdStockPosInfo(storeLocIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('storage/mdStockPosInfo/export', {
        ...this.queryParams
      }, `mdStockPosInfo_${new Date().getTime()}.xlsx`)
    },
    //库房下拉框改变事件
    changeWhId() {
      this.$forceUpdate()
      this.querySelsctParams.whId = this.form.whId || this.forms.whId
      let querySelsctParams = JSON.parse(JSON.stringify(this.querySelsctParams))
      selectMdStorageAreaInfo(querySelsctParams).then(response => {
        this.option = response.data
      })
    },
    //存放区下拉框改变事件
    changeWhAreaId() {
      this.$forceUpdate()
      this.queryMdOptionsParams.whId = this.form.whId || this.forms.whId
      this.queryMdOptionsParams.whAreaId = this.form.whAreaId || this.forms.whAreaId
      let queryMdOptionsParams = JSON.parse(JSON.stringify(this.queryMdOptionsParams))
      this.form.storeAreaId = null;
      this.forms.storeAreaId = null;
      selectMdSaInfo(queryMdOptionsParams).then(response => {
        this.mdStorageOptions = response.data
      })
    },
    //修改数据时下拉框查询事件
    changeSelectChange() {
      this.$forceUpdate()
      this.queryMdOptionsParams.whId = this.form.whId || this.forms.whId
      this.queryMdOptionsParams.whAreaId = this.form.whAreaId || this.forms.whAreaId
      let queryMdOptionsParams = JSON.parse(JSON.stringify(this.queryMdOptionsParams))
      selectMdSaInfo(queryMdOptionsParams).then(response => {
        this.mdStorageOptions = response.data
      })
    },
    //查询参数库区下拉框
    getSelect() {
      let querySelsctParams = {}
      querySelsctParams.whId = 1
      selectMdStorageAreaInfo(querySelsctParams).then(response => {
        this.optionss = response.data
      })
    },
    //查询参数存放区下拉框
    getMessageOption() {
      let queryMdOptionsParams = {}
      queryMdOptionsParams.whId = 1
      queryMdOptionsParams.whAreaId = this.queryParams.whAreaId
      this.queryParams.storeAreaId = null
      selectMdSaInfo(queryMdOptionsParams).then(response => {
        this.messageOption = response.data
      })
    }
  }
};
</script>
<style lang="scss" scoped>
.el-col-11 {
  margin-left: 20px;
}
</style>
